import { useState, useEffect } from "react";

function useTable<Res = any>(url: string) {
  const [data, setData] = useState<Res>();

  useEffect(() => {
    let isMounted = true;
    fetch(url)
      .then(res => res.json())
      .then(res => {
        if (isMounted) {
          setData(res);
        }
      });

    return () => {
      isMounted = false;
    };
  }, []);

  return data;
}

export default useTable;
